﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="产品收发存统计.aspx.cs" Inherits="syc.Store.产品收发存统计" %>
<html>
<head>
</head>
<body>
<script type="text/javascript" language="javascript" src="/common.js"></script>

<form id="form1" runat="server">
<div id="wintop" class="wintop">产品收发存统计</div>
<asp:Panel ID="Panel1" runat="server" GroupingText="统 计" CssClass="panel">

<asp:SqlDataSource ID="DS_ChanPin" runat="server" 
    ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
    SelectCommand="SELECT [ID],[品名]+' '+[钢级]+' '+[规格] AS 名称 FROM [产品]"></asp:SqlDataSource>
产品类别：<asp:DropDownList ID="ChanPin" runat="server" Width="150px" Font-Size="12px" DataSourceID="DS_ChanPin" DataTextField="名称" DataValueField="ID">

</asp:DropDownList>  
<span style="margin-left:20px;"></span>生产单位：<asp:DropDownList ID="FenChang" runat="server" Width="120px">
            <asp:ListItem Value="0">全部</asp:ListItem>
            <asp:ListItem Value="101">一分厂</asp:ListItem>
            <asp:ListItem Value="2">二分厂</asp:ListItem>
            <asp:ListItem Value="201">　二分厂1号线</asp:ListItem>
            <asp:ListItem Value="202">　二分厂2号线</asp:ListItem>
            <asp:ListItem Value="5">五分厂</asp:ListItem>
            <asp:ListItem Value="501">　五分厂1号线</asp:ListItem>
            <asp:ListItem Value="502">　五分厂2号线</asp:ListItem>
        </asp:DropDownList> 
<span style="margin-left:20px;"></span>原料供货：<asp:DropDownList ID="GongHuo" runat="server" 
        DataSourceID="SqlDataSource2" DataTextField="名称" DataValueField="ID" 
        Width="120px">
    </asp:DropDownList>
    
<div style="font-size:6px;height:6px;line-height:6px;"></div>

    日　　期：<asp:TextBox ID="Date1" runat="server" CssClass="intxt1" Width="120px"></asp:TextBox><img alt="" src="/Icons/29.png" align="middle" onclick="makecalendar(document.getElementById('Date1').value, document.getElementById('Date1'));" />
<span style="margin:0px 30px 0px 30px;">至</span><asp:TextBox ID="Date2" runat="server" CssClass="intxt1" Width="120px"></asp:TextBox><img alt="" src="/Icons/29.png" align="middle" onclick="makecalendar(document.getElementById('Date2').value, document.getElementById('Date2'));" />
    
   
<span style="margin-left:20px;"></span><asp:Button ID="Button_Query" runat="server" Text="统 计" CssClass="mbutton" 
        UseSubmitBehavior="False" onclick="Button_Query_Click" />

<asp:Button ID="Button_Reset" runat="server" Text="清空条件" UseSubmitBehavior="false" 
        CssClass="mbutton" onclick="Button_Reset_Click"  />
        
<input type="button" value="导出Excel" class="mbutton" onclick="Export();"/>

    <div style="font-size:6px;height:6px;line-height:6px;"></div>    
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
        SelectCommand="SELECT 0 as [ID], '全部' as [名称] UNION SELECT [ID], [名称] FROM [原料供货单位]"></asp:SqlDataSource>
    <asp:Panel ID="Panel2" runat="server" CssClass="panel">
        <asp:Label ID="Label_Result" runat="server" Text="请点击“统计”按钮进行统计" ForeColor="Red"></asp:Label>
    </asp:Panel>
</asp:Panel>
<style>
td.bb{border:.5pt solid #000000;font-size:11pt;text-align:center;height:22pt;}
</style>
<asp:Panel ID="Panel3" runat="server" CssClass="panel3">
<%
    if (this.report)
    {
        int ttks = 0;
        decimal ttzl = 0;
        decimal ttcd = 0;
        int ttzs = 0;
        int ttds = 0;
        
        int ks = 0;
        decimal zl = 0;
        decimal cd = 0;
        int zs = 0;
        int ds = 0;
        
        string lh = " ";
        string bz = "";
        string dss = ",";
        DateTime d=DateTime.Today;
        
        System.Data.SqlClient.SqlConnection Conn = new System.Data.SqlClient.SqlConnection();
        Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
        Conn.Open();
        System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand();
        Cmd.Connection = Conn;

        string state = this.GetState();
        Cmd.CommandText = "SELECT 入库日期,重量,长度,支数,产品类别ID,捆号,rtrim(炉号),入库单ID FROM 产品库存" + state + " order by 入库日期";
        System.Data.SqlClient.SqlDataReader Reader = Cmd.ExecuteReader();
        if (Reader.Read())
        {
            Response.Write("<table cellpadding=0 bordercolor=#000000 style='border-collapse: collapse;border:1pt solid #000000;'>"
                + "<tr><td class=bb colspan=7 style='height:36pt;font-size:16pt'><b>入 库 明 细</b></td></tr>");
            Response.Write(
    @"<tr>
<td class=bb style='width:3cm'>入库日期</td>
<td class=bb style='width:2.5cm'>入库单数</td>
<td class=bb style='width:2.5cm'>捆数</td>
<td class=bb style='width:2.5cm'>支数</td>
<td class=bb style='width:3cm'>重量(kg)</td>
<td class=bb style='width:3cm'>长度(m)</td>
<td class=bb style='width:6cm'>备注</td>
</tr>");
            do
            {
                if (ks > 0 && d != Reader.GetDateTime(0))
                {
                    if (d.DayOfWeek == DayOfWeek.Sunday)
                    {
                        Response.Write("<tr bgcolor=#ffdddd>");
                    }
                    else
                    {
                        Response.Write("<tr>");
                    }
                    Response.Write("<td class=bb>" + d.ToShortDateString() +"</td>");
                    Response.Write("<td class=bb>" + ds + "</td>");
                    Response.Write("<td class=bb>" + ks + "</td>");
                    Response.Write("<td class=bb>" + zs + "</td>");
                    Response.Write("<td class=bb>" + zl + "</td>");
                    Response.Write("<td class=bb>" + cd + "</td>");
                    Response.Write("<td class=bb style='width:6cm;text-align:left;'>" + bz + " " + lh + "</td></tr>");
                    ks = 0;
                    zl = 0;
                    zs = 0;
                    cd = 0;
                    ds = 0;
                    lh = " ";
                    bz = "";
                    dss = ",";
                }
                d = Reader.GetDateTime(0);
                ks++;
                zl += Reader.GetDecimal(1);
                cd += Reader.GetDecimal(2);
                zs += Reader.GetByte(3);

                ttks++;
                ttzl += Reader.GetDecimal(1);
                ttcd += Reader.GetDecimal(2);
                ttzs += Reader.GetByte(3);

                if (this.ChanPin.Text == "1" && Reader.GetByte(3)!=19)
                {
                    bz += " " +this.GetKunHao(Reader.GetInt32(5))+"为"+ Reader.GetByte(3)+"支";
                }
                if (lh.IndexOf(" "+Reader.GetString(6)+" ") < 0)
                {
                    lh += Reader.GetString(6) + " ";
                }

                if (dss.IndexOf("," + Reader.GetInt32(7).ToString() + ",") <0)
                {
                    dss = dss + Reader.GetInt32(7).ToString() + ",";
                    ds++;
                    ttds++;
                }
            }
            while (Reader.Read());
            if (d.DayOfWeek == DayOfWeek.Sunday)
            {
                Response.Write("<tr bgcolor=#ffdddd>");
            }
            else
            {
                Response.Write("<tr>");
            }
            Response.Write("<td class=bb>" + d.ToShortDateString() + "</td>");
            Response.Write("<td class=bb>" + ds + "</td>");
            Response.Write("<td class=bb>" + ks + "</td>");
            Response.Write("<td class=bb>" + zs + "</td>");
            Response.Write("<td class=bb>" + zl + "</td>");
            Response.Write("<td class=bb>" + cd + "</td>");
            Response.Write("<td class=bb style='width:6cm;text-align:left;'>" + bz + " " + lh + "</td></tr>");
            
            Response.Write(
    @"<tr>
<td class=bb>合计</td>
<td class=bb>" + ttds + @"</td>
<td class=bb>" + ttks + @"</td>
<td class=bb>" + ttzs + @"</td>
<td class=bb>" + ttzl + @"</td>
<td class=bb>" + ttcd + @"</td>
<td class=bb></td>
</tr></table>");

        }
        
        
        
        Response.Write("<br>");
        Reader.Close();
        ttks = 0;
        ttzl = 0;
        ttzs = 0;
        ttcd = 0;
        ttds = 0;
        
        ks = 0;
        zl = 0;
        zs = 0;
        cd = 0;
        ds = 0;
        lh = " ";
        bz = "";
        dss = ",";
        
        if (state=="")
        {
            state = " where 状态=2 and 出库日期 is not null";
        }
        else
        {
            state += " and 状态=2 and 出库日期 is not null";
        }
        
        Cmd.CommandText = "SELECT 出库日期,重量,长度,支数,产品类别ID,捆号,rtrim(炉号),出库单ID FROM 产品库存" + state.Replace("入库", "出库") + " order by 出库日期";

        Reader = Cmd.ExecuteReader();

        if (Reader.Read())
        {
            Response.Write("<table cellpadding=0 bordercolor=#000000 style='border-collapse: collapse;border:1pt solid #000000;'>"
                + "<tr><td class=bb colspan=7 style='height:36pt;font-size:16pt'><b>出 库 明 细</b></td></tr>");
            Response.Write(
    @"<tr>
<td class=bb style='width:3cm'>出库日期</td>
<td class=bb style='width:2.5cm'>出库单数</td>
<td class=bb style='width:2.5cm'>捆数</td>
<td class=bb style='width:2.5cm'>支数</td>
<td class=bb style='width:3cm'>重量(kg)</td>
<td class=bb style='width:3cm'>长度(m)</td>
<td class=bb style='width:6cm'>备注</td>
</tr>");
            do
            {
                if (ks > 0 && d != Reader.GetDateTime(0))
                {
                    if (d.DayOfWeek == DayOfWeek.Sunday)
                    {
                        Response.Write("<tr bgcolor=#ffdddd>");
                    }
                    else
                    {
                        Response.Write("<tr>");
                    }
                    Response.Write("<td class=bb>" + d.ToShortDateString() + "</td>");
                    Response.Write("<td class=bb>" + ds + "</td>");
                    Response.Write("<td class=bb>" + ks + "</td>");
                    Response.Write("<td class=bb>" + zs + "</td>");
                    Response.Write("<td class=bb>" + zl + "</td>");
                    Response.Write("<td class=bb>" + cd + "</td>");
                    Response.Write("<td class=bb style='width:6cm;text-align:left;'>" + bz + " " + lh + "</td></tr>");
                    ks = 0;
                    zl = 0;
                    zs = 0;
                    cd = 0;
                    ds = 0;
                    lh = " ";
                    bz = "";
                    dss = ",";
                }
                d = Reader.GetDateTime(0);
                ks++;
                zl += Reader.GetDecimal(1);
                cd += Reader.GetDecimal(2);
                zs += Reader.GetByte(3);

                ttks++;
                ttzl += Reader.GetDecimal(1);
                ttcd += Reader.GetDecimal(2);
                ttzs += Reader.GetByte(3);

                if (this.ChanPin.Text == "1" && Reader.GetByte(3) != 19)
                {
                    bz += " " + this.GetKunHao(Reader.GetInt32(5)) + "为" + Reader.GetByte(3) + "支";
                }
                if (lh.IndexOf(" " + Reader.GetString(6) + " ") < 0)
                {
                    lh += Reader.GetString(6) + " ";
                }
                if (dss.IndexOf("," + Reader.GetInt32(7).ToString() + ",") < 0)
                {
                    dss = dss + Reader.GetInt32(7).ToString() + ",";
                    ds++;
                    ttds++;
                }
            }
            while (Reader.Read());
            if (d.DayOfWeek == DayOfWeek.Sunday)
            {
                Response.Write("<tr bgcolor=#ffdddd>");
            }
            else
            {
                Response.Write("<tr>");
            }
            Response.Write("<td class=bb>" + d.ToShortDateString() + "</td>");
            Response.Write("<td class=bb>" + ds + "</td>");
            Response.Write("<td class=bb>" + ks + "</td>");
            Response.Write("<td class=bb>" + zs + "</td>");
            Response.Write("<td class=bb>" + zl + "</td>");
            Response.Write("<td class=bb>" + cd + "</td>");
            Response.Write("<td class=bb style='width:6cm;text-align:left;'>" + bz + " " + lh + "</td></tr>");

            Response.Write(
    @"<tr>
<td class=bb>合计</td>
<td class=bb>" + ttds + @"</td>
<td class=bb>" + ttks + @"</td>
<td class=bb>" + ttzs + @"</td>
<td class=bb>" + ttzl + @"</td>
<td class=bb>" + ttcd + @"</td>
<td class=bb></td>
</tr></table>");

        }

        Response.Write("<br>");
        Reader.Close();
        ttks = 0;
        ttzl = 0;
        ttzs = 0;
        ttcd = 0;
        ttds = 0;

        ks = 0;
        zl = 0;
        zs = 0;
        cd = 0;
        ds = 0;
        lh = " ";
        bz = "";
        dss = ",";

        state = this.GetState2();

        Cmd.CommandText = "SELECT 日期,总重量,总长度,总支数,总件数,序号 FROM 产品出库单 " + state + " order by 日期";

        Reader = Cmd.ExecuteReader();

        if (Reader.Read())
        {
            Response.Write("<table cellpadding=0 bordercolor=#000000 style='border-collapse: collapse;border:1pt solid #000000;'>"
                + "<tr><td class=bb colspan=7 style='height:36pt;font-size:16pt'><b>出 库 单 明 细</b></td></tr>");
            Response.Write(
    @"<tr>
<td class=bb style='width:3cm'>出库日期</td>
<td class=bb style='width:2.5cm'>出库单数</td>
<td class=bb style='width:2.5cm'>捆数</td>
<td class=bb style='width:2.5cm'>支数</td>
<td class=bb style='width:3cm'>重量(吨)</td>
<td class=bb style='width:3cm'>长度(m)</td>
<td class=bb style='width:6cm'>备注</td>
</tr>");
            do
            {
                if (ks > 0 && d != Reader.GetDateTime(0))
                {
                    if (d.DayOfWeek == DayOfWeek.Sunday)
                    {
                        Response.Write("<tr bgcolor=#ffdddd>");
                    }
                    else
                    {
                        Response.Write("<tr>");
                    }
                    Response.Write("<td class=bb>" + d.ToShortDateString() + "</td>");
                    Response.Write("<td class=bb>" + ds + "</td>");
                    Response.Write("<td class=bb>" + ks + "</td>");
                    Response.Write("<td class=bb>" + zs + "</td>");
                    Response.Write("<td class=bb>" + (zl/1000) + "</td>");
                    Response.Write("<td class=bb>" + cd + "</td>");
                    Response.Write("<td class=bb style='width:6cm;text-align:left;'>"+bz+"</td></tr>");
                    ks = 0;
                    zl = 0;
                    zs = 0;
                    cd = 0;
                    ds = 0;
                    lh = " ";
                    bz = "";
                    dss = ",";
                }
                d = Reader.GetDateTime(0);
                zl += ((int)(Reader.GetDecimal(1)*10+5))/10;
                cd += Reader.GetDecimal(2);
                zs += Reader.GetInt16(3);
                ks += Reader.GetByte(4);
                ds++;
                bz += " " + Reader.GetInt32(5);
                
                ttks += Reader.GetByte(4);
                ttds++;
                ttzl += ((int)(Reader.GetDecimal(1) * 10 + 5)) / 10;
                ttcd += Reader.GetDecimal(2);
                ttzs += Reader.GetInt16(3);

            }
            while (Reader.Read());
            if (d.DayOfWeek == DayOfWeek.Sunday)
            {
                Response.Write("<tr bgcolor=#ffdddd>");
            }
            else
            {
                Response.Write("<tr>");
            }
            Response.Write("<td class=bb>" + d.ToShortDateString() + "</td>");
            Response.Write("<td class=bb>" + ds + "</td>");
            Response.Write("<td class=bb>" + ks + "</td>");
            Response.Write("<td class=bb>" + zs + "</td>");
            Response.Write("<td class=bb>" + (zl / 1000) + "</td>");
            Response.Write("<td class=bb>" + cd + "</td>");
            Response.Write("<td class=bb style='width:6cm;text-align:left;'>" + bz + " " + lh + "</td></tr>");

            Response.Write(
    @"<tr>
<td class=bb>合计</td>
<td class=bb>" + ttds + @"</td>
<td class=bb>" + ttks + @"</td>
<td class=bb>" + ttzs + @"</td>
<td class=bb>" + (ttzl / 1000) + @"</td>
<td class=bb>" + ttcd + @"</td>
<td class=bb></td>
</tr></table>");

        }
        Reader.Close();
        
        
        Reader.Dispose();
        Cmd.Dispose();
        Conn.Close();
        Conn.Dispose();
    }
 %>
</asp:Panel>
</form>
<form id="form2" method="post" action="/PageExport.ashx">
<input type="hidden" name="filename" value="产品入出库明细.xls" />
<input type="hidden" name="content" value="" />
</form>
<script>
    //导出Excel
    function Export() {
        form2.content.value =
"<html xmlns:o='urn:schemas-microsoft-com:office:office'\nxmlns:x='urn:schemas-microsoft-com:office:excel'\nxmlns='http://www.w3.org/TR/REC-html40'>\n<head>\n<meta http-equiv=Content-Type content='text/html; charset=utf-8'>\n<style>\n<!--table\n@page\n{mso-header-data:;\nmso-footer-data:;\nmargin:.79in .31in .79in .31in;\nmso-header-margin:.51in;\nmso-footer-margin:.51in;\nmso-horizontal-page-align:center;\n}td.bb{border:.5pt solid black;text-align:center;}\n-->\n</style>\n<!--[if gte mso 9]><xml>\n<x:ExcelWorkbook>\n<x:ExcelWorksheets>\n<x:ExcelWorksheet>\n<x:Name>产品入出库明细</x:Name>\n<x:WorksheetOptions>\n<x:DefaultRowHeight>285</x:DefaultRowHeight>\n<x:Print>\n<x:ValidPrinterInfo/>\n<x:Scale>100</x:Scale>\n<x:PaperSizeIndex>9</x:PaperSizeIndex>\n<x:HorizontalResolution>200</x:HorizontalResolution>\n<x:VerticalResolution>200</x:VerticalResolution>\n</x:Print>\n<x:Selected/>\n<x:Panes>\n<x:Pane>\n<x:Number>3</x:Number>\n<x:ActiveRow>0</x:ActiveRow>\n<x:ActiveCol>0</x:ActiveCol>\n</x:Pane>\n</x:Panes>\n</x:WorksheetOptions>\n</x:ExcelWorksheet>\n</x:ExcelWorkbook>\n</xml><![endif]-->\n</head>\n<body>"
        + Panel3.innerHTML + "</body></html>";
        form2.submit();
    }
</script>
</body>
</html>
